<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-11-02
 * Time: 15:49
 */

namespace app\domain;



use app\src\order\action\IntentionalOrderCreateAction;
use app\src\order\action\IntentionalOrderQueryAction;

class IntentionalOrderDomain extends BaseDomain
{
    /**
     * 创建意向订单
     * @author hebidu <email:346551990@qq.com>
     */
    public function create(){

        //商品skuid,逗号分割
        $sku_ids = $this->_post('sku_ids','');
        $sku_ids = trim(trim($sku_ids),",");

        $p_ids = $this->_post('p_ids','');
        $p_ids = trim(trim($p_ids),",");

        if(empty($sku_ids) && empty($p_ids)){
            $this->apiReturnErr(lang('invalid_parameter',['param'=>'ids']));
        }

        //uid所需
        $uid = $this->_post('uid','',lang('uid_need'));
        $contact_name = $this->_post('contact_name','');
        $note = $this->_post('note','');

        $action = new IntentionalOrderCreateAction();

        $result = $action->create($uid,$sku_ids,$p_ids,$contact_name,$note);

        $this->exitWhenError($result,true);
    }

    /**
     * 意向订单查询
     * @author hebidu <email:346551990@qq.com>
     */
    public function query(){

        //uid所需
        $uid = $this->_post('uid','',lang('uid_need'));
        $page_index = $this->_post('page_index',1);
        $page_size = $this->_post('page_size',10);

        $action = new IntentionalOrderQueryAction();

        $result = $action->query($uid,$page_index,$page_size);

        $this->exitWhenError($result,true);
    }
}